using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

using Common;

using GrpcClient.Interfaces;
using GrpcClient.Models;
using GrpcClient.Services;
using GrpcClient.Utility;

using GRPCDemo.Protocol;

namespace GrpcClient.Managers
{
    public class UserManager : Singleton<UserManager>, IManager
    {
        public User? CurrentUser;
        public bool IsLogin => CurrentUser != null;
        public bool IsRegister = false;

        public void Start()
        {
            CommonUtility.NotifyMessageEvent += NotifyMessage;
        }

        public void Stop()
        {
            CommonUtility.NotifyMessageEvent -= NotifyMessage;
        }

        public async Task Login(string name, string password)
        {
            CurrentUser = new User(new NUserInfo { Name = name, Level = 0, Uid = "0001"});
            //string messageId = UserService.Instance.OnLogin(name, password);
            //await CommonUtility.Wait(UserService.Instance.MessageCache[messageId]);
        }

        public async Task Register(string name, string password)
        {
            //string messageId = UserService.Instance.OnRegister(name, password);
            //await CommonUtility.Wait(UserService.Instance.MessageCache[messageId]);
        }

        public async Task LoginOut()
        {
            if (CurrentUser == null) return;
            CurrentUser = null;
            //string messageId = UserService.Instance.OnLoginOut(CurrentUser.Name);
            //await CommonUtility.Wait(UserService.Instance.MessageCache[messageId]);
        }

        private void NotifyMessage(string obj)
        {
            MessageBox.Show(obj);
        }
    }
}
